package org.noip.milhous.clause;

import org.noip.milhous.SQLInterface;

public class Function implements SQLInterface
{

	public enum FUNCTIONS
	{
		SUM,
		COUNT,
		CONNECTION("CONNECTION_ID");
		String functionName;

		private FUNCTIONS()
			{
				functionName = name();
			}

		private FUNCTIONS(String s)
			{
				functionName = s;
			}

		public String getFunctionName()
			{
				return functionName;
			}
	};

	String sql;

	public Function(FUNCTIONS f, String name)
		{
			this(f, null, name);
		}

	public Function(FUNCTIONS f, Object field, String name)
		{
			String fname = "*";
			if (field != null)
				{
					fname = Utilities.getField(field);
				}
			sql = " " + f.getFunctionName() + "(" + fname + ") as " + name + " ";
		}

	public String toSQL()
		{
			return sql;
		}

	public String toInternalSQL()
		{
			return toSQL();
		}

}
